﻿using System.Collections.Generic;
using System.Linq;
using Core.DAL;
using Core.Utils;
using System;

namespace Core.BOL
{
    public class MailQueueRepository : IDisposable
    {
        private ScoutNetDataContext context = null;

        #region Construtor
        public MailQueueRepository()
        {
            context = GeneralUtils.GetDataContext();
        }
        #endregion

        #region Methodes
        public List<tMail_Queue> GetMail(int numItem)
        {
            var query = (from mq in context.tMail_Queues
                         orderby mq.InsertDate
                         select mq).Take(numItem).ToList();
            return query;
        }

        public void DeleteMail(int id)
        {
            tMail_Queue tMail = context.tMail_Queues.Single(p => p.ID == id);
            if (tMail != null)
            {
                context.tMail_Queues.DeleteOnSubmit(tMail);
            }
        }

        public void InsertMail(tMail_Queue mail)
        {
            context.tMail_Queues.InsertOnSubmit(mail);
        }

        public void Save()
        {
            context.SubmitChanges();
        }
        
        public void Dispose()
        {
            context.Dispose();
        }
        #endregion
    }
}
